//
//  LTLframeModel.m
//  WeiBo
//
//  Created by Apple_Lzzy46 on 16/10/19.
//  Copyright © 2016年 LTL. All rights reserved.
//

#import "LTLframeModel.h"

@implementation LTLframeModel

-(void)setModel:(LTLhomeModel *)model
{
    _model = model;
    
    //文本大小
//    NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:18]};
//    
//    self.nameSize = [_model.user.name boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
//    
//    NSLog(@"%@  %@  ",model.user.name , NSStringFromCGSize(self.nameSize));
    //头像位置
    self.iconFrame = CGRectMake(15, 15, 50, 50);
    
    
    //name文本大小
    CGSize nameSize = [model.user.name sizeTextFont:[UIFont systemFontOfSize:18]];
    //    self.name.x = CGRectGetMaxX(self.icon.frame) + 10;
    //    self.name.y = CGRectGetMinY(self.icon.frame) ;
    
    self.nameFrame = CGRectMake(CGRectGetMaxX(self.iconFrame) + 10, CGRectGetMinY(self.iconFrame), nameSize.width, nameSize.height);
    
//    //时间位置
//    CGSize timeSize = [self sizeText:model.created_at Font:[UIFont systemFontOfSize:12]];
//    self.created_atFrame = CGRectMake(CGRectGetMaxX(self.iconFrame) + 10, CGRectGetMaxY(self.iconFrame)-timeSize.height, timeSize.width, timeSize.height);
    
//    //来源文本位置
//    CGSize sourceSize = [self sizeText:model.source Font:[UIFont systemFontOfSize:12]];
//    self.sourceFrame = CGRectMake(CGRectGetMaxX(self.created_atFrame) + 10, CGRectGetMinY(self.created_atFrame), sourceSize.width, sourceSize.height);
    
    //VIP 位置
    self.vipFrame = CGRectMake(CGRectGetMaxX(self.nameFrame) , CGRectGetMinY(self.nameFrame), 19, 19);
    
    CGFloat w = 18;
    self.vFrame = CGRectMake(CGRectGetMaxX(self.iconFrame)-w , CGRectGetMaxY(self.iconFrame)-w, w, w);
    
    //正文位置
    if (_model.text) {
        //文本大小
        NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:18]};
        CGSize size =[_model.text boundingRectWithSize:CGSizeMake(mainWidth-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
        
        self.textFrame = CGRectMake(15, CGRectGetMaxY(_iconFrame)+10, size.width, size.height);
        
    } else {
        
        self.textFrame = CGRectMake(15, CGRectGetMaxY(_iconFrame)+10, 0, 0);
    }
    NSInteger count = _model.pic_urls.count;
    NSUInteger row = 0;
//    CGFloat width = (mainWidth-30-20)/3;
    if (_model.pic_urls.count != 0) {
        //行
         if((count == 5)||(count == 6))
        {
            row = (mainWidth-40);
        }
        else if (count == 2)
        {
            row = (mainWidth-40)/2;
        }
        else
        {
            row = mainWidth-30;
        }
    //配图位置
    self.pictureFrame = CGRectMake(CGRectGetMinX(self.textFrame), CGRectGetMaxY(self.textFrame)+10, mainWidth-30, row);
    //原创微博容器高度
    self.OriginalHeight = CGRectGetMaxY(self.pictureFrame)+10;
        
    } else {
       //配图位置
        self.pictureFrame = CGRectZero;
        //原创微博容器高度
        self.OriginalHeight = CGRectGetMaxY(self.textFrame)+10;
        
    }
    if (model.retweeted_status) {
//        NSLog(@"%@  转发  %@", model.user.name, model.retweeted_status.user.name);
        //文本大小
        NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:18]};
        
        NSString *text = [NSString stringWithFormat:@"@%@: %@", model.retweeted_status.user.name , model.retweeted_status.text];
        
        CGSize size =[text boundingRectWithSize:CGSizeMake(mainWidth-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
        
        self.forwardTextFrame = CGRectMake(15, 10, size.width, size.height);
        //配图
        if (_model.retweeted_status.pic_urls.count != 0) {
            
            NSInteger count = _model.retweeted_status.pic_urls.count;
            CGFloat w ;
            if((count == 5)||(count == 6))
            {
                w = (mainWidth-40);
            }
            else if (count == 2)
            {
                w = (mainWidth-40)/2;
            }
            else
            {
                w = mainWidth-30;
            }
            //配图位置
            self.forwardPictureFrame = CGRectMake(CGRectGetMinX(self.forwardTextFrame), CGRectGetMaxY(self.forwardTextFrame)+10, mainWidth-30, w);
            //原创微博容器高度
            self.forwardHeight = CGRectGetMaxY(self.forwardPictureFrame)+10;
            
        } else {
            //配图位置
            self.forwardPictureFrame = CGRectZero;
            //原创微博容器高度
            self.forwardHeight = CGRectGetMaxY(self.forwardTextFrame)+10;
              
        }

        
    }
    else
    {
//       NSLog(@"%@  没有转发", model.user.name);
     self.forwardHeight = 0;
    }
    self.DIHeight = 38;
}

-(CGRect)created_atFrame
{
    //时间位置
    CGSize timeSize = [_model.created_at sizeTextFont:[UIFont systemFontOfSize:12]];
    
    return CGRectMake(CGRectGetMaxX(self.iconFrame) + 10, CGRectGetMaxY(self.iconFrame)-timeSize.height, timeSize.width, timeSize.height);
}

-(CGRect)sourceFrame
{
    //来源文本位置
    CGSize sourceSize = [_model.source sizeTextFont:[UIFont systemFontOfSize:12]];
    
    return  CGRectMake(CGRectGetMaxX(self.created_atFrame) + 10, CGRectGetMinY(self.created_atFrame), sourceSize.width, sourceSize.height);
}



@end
